package util

import (
	"crypto/sha1"
	"encoding/hex"
	"encoding/json"

	"go.uber.org/zap"
)

type TradeData struct {
	TradeID             string `form:"trade_id" json:"trade_id" binding:"required"`                           // 订单id
	TradeSn             string `form:"trade_sn" json:"trade_sn" binding:"required"`                           // 订单 编号
	UserID              string `form:"user_id" json:"user_id" binding:"required"`                             // 用户 id
	SnapTime            string `form:"snap_time" json:"snap_time" binding:"required"`                         // yyyyMMddHHmmssSSS
	LicensePlateNumber  string `form:"license_plate_number" json:"license_plate_number" binding:"required"`   // 车牌前车牌号码，不含颜色，无车牌时，默认"A00000"
	LicensePlateNumber2 string `form:"license_plate_number2" json:"license_plate_number2" binding:"required"` // 车牌后车牌号码，不含颜色，无车牌时，默认"A00000"
	RecordIDs           string `form:"record_ids" json:"record_ids" binding:"required"`                       // PortalRecord的id，用逗号链接，1,2,3,4
	RecordProvinceCodes string `form:"record_province_codes" json:"record_province_codes" binding:"required"` // PortalRecord的province code,用逗号链接，贵州44，深圳33

	Prices     string `form:"prices" json:"prices" binding:"required"`           // 收费, 每一段的收费，用逗号链接，123，2234
	TotalPrice string `form:"total_price" json:"total_price" binding:"required"` // 总价
}

// GenerateTradeRecordEnvidence 生成envidence 哈希的值
func GenerateTradeRecordEnvidence(tradeData *TradeData) (hashText string, err error) {
	portalDataBytes, err := json.Marshal(tradeData)
	if err != nil {
		return "", err
	}
	ins := sha1.New()
	ins.Write(portalDataBytes)
	result := hex.EncodeToString(ins.Sum(nil))
	zap.L().Debug(result)
	return result, nil
}
